#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
__int128_t val[maxn];
__int128_t kd[maxn];
__int128_t ans[maxn];
__int128_t qe[maxn];
inline __int128_t read(){
    __int128_t x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void print(__int128_t x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

bool cmp(__int128_t a,__int128_t b)
{
	return b<a;
}
int main()
{
	int t;
	int cnt = 0;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		ans[0] = 0;
		__int128_t maxx = -1e18;
		int flag = 0;
		for(int i = 1;i<=n;i++)
		{
			val[i] = read();
			ans[i] = ans[i-1]+val[i];
			if(maxx<ans[i]) 
			{
				maxx = ans[i];
				flag = i;
			}
		}
		for(int i = 1;i<=flag;i++)
		{
			qe[i] = ans[i];
		}
		sort(qe+1,qe+1+flag,cmp);
		kd[0] = 1e18;
		for(int i = 1;i<=n;i++)
		{
			kd[i] = read();
			if(kd[i]>kd[i-1]) kd[i] = kd[i-1];
		}
		__int128_t num = kd[1];
		__int128_t sum = 0;
		long long dec = 0;
		int zz = 1;
		for(int i = flag;i>=1;i--)
		{
			if(ans[i]==qe[zz])
			{
				dec += kd[i];
				sum += ans[i]*kd[i];
				kd[i-1] -= dec;
				zz++; 
			}
			else kd[i-1] -= dec;
		}
		printf("Case #%d: ",++cnt);
		print(num);
		printf(" ");
		print(sum);
		printf("\n");
	}
} 
